(function () {
    const p = document.querySelector('.yzm .pa')
    let flag = true
    p.addEventListener('click', function () {
        if (flag) {
            flag = false
            p.innerHTML = '05秒后重新获取'
            let i = 5;
            let n = setInterval(function () {
                i--
                p.innerHTML = `0${i}秒后重新获取`
                if (!i) {
                    clearInterval(n)
                    p.innerHTML = '重新获取'
                    flag = true
                }
            }, 1000)
        }
    })

}());




const ph = document.querySelector('[name=phonenum]')
ph.addEventListener('change', verfyph)

function verfyph() {
    const reg = /^1[3-9]\d{9}$/
    const span = ph.nextElementSibling
    if (!reg.test(ph.value)) {

        span.className = 'error '
        span.innerHTML = '<i class="error_icon"></i>手机号码格式不正确，请重新输入';
        ff1 = 0
        return false
    }
    else {
        span.className = 'success '
        span.innerHTML = '<i class="success_icon"></i>输入正确'
        ff1 = 1
        return true
    }
}






const phyzm = document.querySelector('[name=yzmdc]')
phyzm.addEventListener('change', veyzm)

function veyzm() {
    const reg = /^\d{6}$/
    const span = document.querySelector('.spann1')
    if (!reg.test(phyzm.value)) {
        span.className = 'error spann1'
        span.innerHTML = '<i class="error_icon"></i>验证码格式不正确，请重新输入';
        return false
    }
    else {
        span.className = 'success spann1'
        span.innerHTML = '<i class="success_icon"></i>输入正确'
        return true
    }
}



const psw = document.querySelector('[name=passwordp]')
psw.addEventListener('change', verfypsw)

function verfypsw() {
    const reg = /^[a-zA-Z0-9-_]{6,20}$/
    const span = psw.nextElementSibling
    if (!reg.test(psw.value)) {

        span.className = 'error '
        span.innerHTML = '<i class="error_icon"></i>格式错误，输入(6~20位数字、字母、下划线)';
        return false
    }
    else {
        span.className = 'success '
        span.innerHTML = '<i class="success_icon"></i>输入正确'
        return true
    }
}


const pph = document.querySelector('[name=confirm]')
pph.addEventListener('change', verfypph)

function verfypph() {

    const span = pph.nextElementSibling
    if (pph.value !== psw.value) {

        span.className = 'error '
        span.innerHTML = '<i class="error_icon"></i>两次密码不同';
        return false
    }
    else {
        span.className = 'success '
        span.innerHTML = '<i class="success_icon"></i>输入正确'
        return true
    }
}


const queren = document.querySelector('[name=queren]')

const sub = document.querySelector('.sub input')
sub.addEventListener('click', function (e) {
    if (!queren.checked) {
        alert('请勾选同意协议')
        e.preventDefault()
    }
    if (!(verfyph() && veyzm() && verfypsw() && verfypph())) {
        e.preventDefault()
    }
    // console.log(queren.checked)
})


